package net.linxuehua.server.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import net.linxuehua.server.dao.CookDao;
import net.linxuehua.server.po.Cook;
import net.linxuehua.server.service.CookService;
import org.springframework.stereotype.Service;

import java.util.Calendar;
import java.util.Date;

/**
 * Cook对应service实现
 *
 * @author codeGenerate 2021年01月13日
 */
@Service
public class CookServiceImpl extends ServiceImpl<CookDao, Cook> implements CookService {
    @Override
    public boolean isOutTime(Date date) {
        Date time_now = new Date();
        long diff = 0;
        String CountTime = "";
        int year = 0, month = 0, day = 0;
        long hours = 0, minutes = 0, s = 0;
        Date time_ago = date;
        diff = time_now.getTime() - time_ago.getTime();
        //当前系统时间转Calendar类型
        Calendar calendar = Calendar.getInstance();
        calendar.clear();
        calendar.setTime(time_now);
        Calendar currentTimes = calendar;
        //查询的数据时间转Calendar类型
        Calendar calendar1 = Calendar.getInstance();
        calendar.clear();
        calendar.setTime(time_ago);
        Calendar pastTimes = calendar1;
        year = currentTimes.get(Calendar.YEAR) - pastTimes.get(Calendar.YEAR);//获取年
        month = currentTimes.get(Calendar.MONTH) - pastTimes.get(Calendar.MONTH);
        day = currentTimes.get(Calendar.DAY_OF_MONTH) - pastTimes.get(Calendar.DAY_OF_MONTH);
        if (month < 0) {
            month = (month + 12) % 12;//获取月
            year--;
        }
        if (day < 0) {
            month -= 1;
            currentTimes.add(Calendar.MONTH, -1); //减一个月
            day = day + currentTimes.getActualMaximum(Calendar.DAY_OF_MONTH);//获取日
        }

        long days = diff / (1000 * 60 * 60 * 24);
        hours = (diff - days * (1000 * 60 * 60 * 24)) / (1000 * 60 * 60); //获取时
        minutes = (diff - days * (1000 * 60 * 60 * 24) - hours * (1000 * 60 * 60)) / (1000 * 60);  //获取分钟
        s = (diff / 1000 - days * 24 * 60 * 60 - hours * 60 * 60 - minutes * 60);//获取秒
        if (minutes > 5 || days > 0) {
            return false;
        }
        return true;
    }

    @Override
    public String toString(int[] a) {
        StringBuffer str = new StringBuffer();
        for (int i = 0; i < a.length; i++) {
            str = str.append(a[i]);
            if (i != a.length - 1) {
                str = str.append(",");
            }
        }
        String string = str.toString();
        return string;
    }
}
